

/*******************************************************************************
 * Include files
 ******************************************************************************/
//#include "wlt2325_hc32f460_lqfp64_v1.h"

#include "bsp_print.h"


void DebugUsartErrIrqCallback()
{
    if (Set == USART_GetStatus(BSP_PRINTF_DEVICE, UsartFrameErr))
    {
        USART_ClearStatus(BSP_PRINTF_DEVICE, UsartFrameErr);
    }
    else
    {
    }

    if (Set == USART_GetStatus(BSP_PRINTF_DEVICE,UsartParityErr))
    {
        USART_ClearStatus(BSP_PRINTF_DEVICE, UsartParityErr);
    }
    else
    {
    }

    if (Set == USART_GetStatus(BSP_PRINTF_DEVICE, UsartOverrunErr))
    {
        USART_ClearStatus(BSP_PRINTF_DEVICE, UsartOverrunErr);
			  USART_RecData(BSP_PRINTF_DEVICE);
			
    }
    else
    {
    }
}



/**
 * @brief  BSP printf port initialize
 * @param  None
 * @retval None
 */
void BspPrintfPortInit(void)
{
    /* JTDI Disable Jtag */
    PORT_DebugPortSetting(TDI,Disable);
    PORT_SetFunc(BSP_PRINTF_PORT, BSP_PRINTF_PIN, BSP_PRINTF_PORT_FUNC,Disable);
	  PORT_SetFunc(BSP_DUART_RX_PORT,BSP_DUART_RX_PIN,BSP_DUART_RX_FUNC,Disable);
	
}

void BspPrintfInit(void)
{
	
	stc_irq_regi_conf_t stcIrqRegiConf;
	MEM_ZERO_STRUCT(stcIrqRegiConf);
	
	/* Configures UART for printing. Baud rate 115200. */
	DDL_PrintfInit(BSP_PRINTF_DEVICE, BSP_PRINTF_BAUDRATE, BspPrintfPortInit);

	/* Set USART RX error IRQ */
	stcIrqRegiConf.enIRQn = BSP_DEBUG_UART_ERR_IRQ_NUM;
	stcIrqRegiConf.pfnCallback = &DebugUsartErrIrqCallback;
	stcIrqRegiConf.enIntSrc = BSP_DEBUG_USART_EI_NUM;
	enIrqRegistration(&stcIrqRegiConf);
	NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
	NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
	NVIC_EnableIRQ(stcIrqRegiConf.enIRQn);
	
	USART_FuncCmd(BSP_PRINTF_DEVICE,UsartRxInt,Enable);
	
}

void DDL_Printf_Buf(uint8_t *buf, int len)
{
    int j;
    for(j=0;j<len;j++)
    {
        DDL_Printf(" %02x",buf[j]);
    }
}

